import Login from './pages/login'
import Home from './pages/home'

import { useContext } from "react"
import {Observer} from 'mobx-react'
import {ContextAPI} from './index'
import Routes from './routes/index'
import { Route } from 'react-router-dom'
// import { useHistory } from "react-router-dom";


 
function App(){
    const context = useContext(ContextAPI);
    // let history = useHistory();
    // console.log(context);
    // console.log(context.data);
    // 判断用户是否登录
    const toPage=(data)=>{
        // console.log(data[0].com_um);
        if(!data.length){
            return <Route  path="/login"> <Login></Login></Route>
        }
        if(data[0].com_um){
            // console.log(1111);
            // return  <Route path='/home'><Home/></Route>
            return <Routes></Routes>
        }else{
            // console.log(2222);
            return  <Route  path="/login"> <Login></Login></Route>
            
        }
    }
    return (
        <Observer>
            {()=>toPage(context.data)}
        </Observer>
    )
}

// function App(){
//     return <div>
//         {/* <Home></Home> */}
//         <Routes />
//     </div>
// }
export default App